package com.yk.anima.controller;

import com.yk.anima.api.AdminApi;
import com.yk.anima.pojo.Admin;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.AdminServlet;
import com.yk.anima.util.MD5Utils;
import com.yk.anima.util.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

/**
 * @author xiaokai
 * @create 2021-05-13 09:12:01
 * @desc...用户登录接口
 */

@RequestMapping("/user")
@RestController
public class AdminController implements AdminApi {

    @Autowired
    AdminServlet adminServlet;

    @Autowired
    StringRedisTemplate stringRedisTemplate;


    /**
     * @param userName
     * @param passWord
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 登陆接口
     * @Date 16:45 2021/5/13
     */
    @Override
    @GetMapping("/login/{userName}/{passWord}/{validateCode}")
    public Admin login(@PathVariable("userName") String userName,
                       @PathVariable("passWord") String passWord, @PathVariable("validateCode") String validateCode) {
        String pass = MD5Utils.md5(passWord);
        System.out.println(userName + passWord + pass + validateCode);
        return adminServlet.login(userName, pass, validateCode);

    }

    /**
     * @param id
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 用户退出
     * @Date 18:09 2021/5/13
     */
    @Override
    @GetMapping("/exit/{id}")
    public ResponseResult exit(@PathVariable("id") int id) {
        return adminServlet.exit(id);
    }

    /**
     * @param admin
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 用户注册
     * @Date 17:10 2021/5/15
     */
    @Override
    @PostMapping("/registration")
    public ResponseResult registration(@RequestBody Admin admin) {
        return adminServlet.registration(admin);
    }

    /**
     * @param
     * @return java.lang.String
     * @Author xiaoKai
     * @Description 生成6位数验证码
     * @Date 17:20 2021/5/15
     */
    @Override
    @GetMapping("/verification")
    public String verification(){
        return adminServlet.add();
    }


}

